package com.ysd.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ysd.entity.Statistics;
import com.ysd.repository.StatisticsRepository;
import com.ysd.util.Result;

@RestController
public class StatisticsController {
	@Autowired
	private StatisticsRepository statisticsRepository;
	
	@RequestMapping("findByStatisticsByDay")
	public Object findByStatisticsByDay() {
		List<Object> dList = statisticsRepository.findByStatisticsByDay();
		if (dList != null) {
			return Result.toClient("0", "查询成功", dList);
		} else {
			return Result.toClient("1", "查询失败", dList);
		}
	}
	
	@RequestMapping("findByStatisticsByMonth")
	public Object findByStatisticsByMonth() {
		List<Object> mList = statisticsRepository.findByStatisticsByMonth();
		if (mList != null) {
			return Result.toClient("0", "查询成功", mList);
		} else {
			return Result.toClient("1", "查询失败", mList);
		}
	}
	
	@RequestMapping("findByStatisticsByYear")
	public Object findByStatisticsByYear() {
		List<Object> yList = statisticsRepository.findByStatisticsByYear();
		if (yList != null) {
			return Result.toClient("0", "查询成功", yList);
		} else {
			return Result.toClient("1", "查询失败", yList);
		}
	}
	
	
	@RequestMapping("findByStatisticsByName")
	public Object findByStatisticsByName() {
		System.out.println(1);
		List<Object> nList = statisticsRepository.findByStatisticsByName();
		System.out.println(2);
		System.out.println(nList);
		if (nList != null) {
			return Result.toClient("0", "查询成功", nList);
		} else {
			return Result.toClient("1", "查询失败", nList);
		}
	}
}
